function bucketSort(arr) {
    let max = arr[0];
    let min = arr[0];
    // 获取最大小值 n
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }
        if (arr[i] < min) {
            min = arr[i];
        }
    }
    // 确定桶个数
    const bucketLength = arr.length;
    // 创建桶 n
    const bucketList = new Array(bucketLength);
    for (let i = 0; i < bucketList.length; i++) {
        bucketList[i] = new Array();
    }
    // 遍历原数组，对应元素放入区间 n
    for (let i = 0; i < arr.length; i++) {
        const bucketIndex = Math.floor(
            (arr[i] - min) * ((bucketLength - 1) / (max - min))
        );
        bucketList[bucketIndex].push(arr[i]);
    }
    // 遍历桶 分布均匀n，不均匀nlogn
    for (let i = 0; i < bucketLength; i++) {
        bucketList[i].sort();
    }
    // 输出 n
    const sortedArray = new Array(arr.length);
    let index = 0;
    for (let i = 0; i < bucketList.length; i++) {
        for (let j = 0; j < bucketList[i].length; j++) {
            sortedArray[index++] = bucketList[i][j];
        }
    }
    return sortedArray;
}

const arr = [4.12,6.421,0.0023,3.0,2.123,8.122,4.12, 10.09];
// const arr = [4.5, 0.84, 3.25, 0.5];
const sortedArray = bucketSort(arr);
console.log(sortedArray);
